<template>
  <a-tag style="margin-left:2%" size="medium"  color="gray">
    <template #icon>
      <icon-storage />
    </template>
    订单号 : {{ orderInfo?.order_no}}
  </a-tag>
  <a-tag style="margin-left:1%" size="medium" color="gray">
    <template #icon>
      <icon-user />
    </template>
    客户 : {{ orderInfo?.user?.nickname}}
  </a-tag>
  <a-tag style="margin-left:1%" size="medium" color="gray">
    <template #icon>
      <icon-history />
    </template>
    下单时间 : {{ orderInfo?.created_at}}
  </a-tag>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #warehouse_id="{ record }">
        <!-- 对标题加上 tag -->
        <a-tag v-if="!record.warehouse" color="blue">待入库</a-tag>
        <a-tag v-else color="blue">{{ record?.warehouse?.name }}</a-tag>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import warehouseOrderRecord from '@/api/warehouse/warehouseOrderRecord'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const warehouse_id = ref()
const orderInfo = ref({
})

const open = (row) => {
  warehouse_id.value = row.id
  orderInfo.value = row
  crudRef.value.crudSearchRef.resetSearch();
  crudRef.value.requestData()
}


const numberOperation = (newValue, id, numberName) => {
  warehouseOrderRecord.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  warehouseOrderRecord.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_warehouse_order_record',
  // rowSelection: {
  //   showCheckedAll: false
  // },
  pk: 'id',
  bordered: {cell:true},
  showTools:false,
  showIndex:false,
  expandSearch:false,
  operationColumn: false,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: warehouseOrderRecord.getList,
  recycleApi: warehouseOrderRecord.getRecycleList,
  add: {
    show: false,
    api: warehouseOrderRecord.save,
    auth: ['warehouse:orderRecord:save']
  },
  edit: {
    show: false,
    api: warehouseOrderRecord.update,
    auth: ['warehouse:orderRecord:update']
  },
  delete: {
    show: false,
    api: warehouseOrderRecord.deletes,
    auth: ['warehouse:orderRecord:delete'],
    realApi: warehouseOrderRecord.realDeletes,
    realAuth: ['warehouse:orderRecord:realDeletes']
  },
  recovery: {
    show: false,
    api: warehouseOrderRecord.recoverys,
    auth: ['warehouse:orderRecord:recovery']
  },
  import: {
    show: false,
    url: 'warehouse/orderRecord/import',
    templateUrl: 'warehouse/orderRecord/downloadTemplate',
    auth: ['warehouse:orderRecord:import']
  },
  export: {
    show: true,
    url: 'warehouse/orderRecord/export',
    auth: ['warehouse:orderRecord:export']
  },
  beforeRequest: (params) => {
      params.warehouse_order_id = warehouse_id.value
      params.order = 'created_at'
      params.orderType = 'desc'
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  // {
  //   title: "订单ID",
  //   dataIndex: "warehouse_order_id",
  //   formType: "input",
  //   search: true,
  //   commonRules: {
  //     required: true,
  //     message: "请输入订单ID"
  //   }
  // },
  {
    title: '订单号',
    dataIndex: 'warehouse_order_id',
    align:'center',
    formType: 'select',
    hide:true,
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'warehouse/order/remote',
        // 指定组件接收的props
        props: { label: 'order_no', value: 'id' },
        // 开启分页
        openPage: true,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序
            sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'order_no' ],
            // 设置数据过滤
            filter: {
            },
            // 关联模型
            relations: [
            ]
        }
    }
  },
  {
    title: '客户姓名',
    dataIndex: 'user_id',
    align:'center',
    formType: 'select',
    hide:true,
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'system/user/remote',
        // 指定组件接收的props
        props: { label: 'username', value: 'id' },
        // 开启分页
        openPage: true,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序
            sort: { username: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'username' ],
            // 设置数据过滤
            filter: {
            },
            // 关联模型
            relations: [
            ]
        }
    }
  },
  {
    title: "车号",
    dataIndex: "prediction.car_no",
    align:'center',
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    search: false,
  },
  {
    title: '存放仓库',
    dataIndex: 'warehouse_id',
    align:'center',
    formType: 'select',
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'warehouse/master/remote',
        // 指定组件接收的props
        props: { label: 'name', value: 'id' },
        // 开启分页
        openPage: true,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序
            sort: { id: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'name' ],
            // 设置数据过滤
            filter: {
            },
            // 关联模型
            relations: [
            ]
        }
    }
  },
  {
    title: "品名",
    dataIndex: "prediction.goods_name",
    align:'center',
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    search: false,
  },
  // {
  //   title: "仓位ID",
  //   dataIndex: "warehouse_childs_id",
  //   formType: "input",
  //   search: true,
  //   commonRules: {
  //     required: true,
  //     message: "请输入仓位ID"
  //   }
  // },
  {
    title: "仓位（横）",
    dataIndex: "horizontal_position",
    align:'center',
    formType: "input",
    search: true
  },
  {
    title: "仓位（纵）",
    dataIndex: "release_position",
    align:'center',
    formType: "input",
    search: true
  },
  {
    title: "仓位（层）",
    dataIndex: "reaches_position",
    align:'center',
    formType: "input",
    search: true
  },
  {
    title: "托管状态",
    dataIndex: "status",
    formType: "select",
    align:'center',
    search: true,
    dict: {
      data: [
        {
          label: "免费托管",
          value: "1"
        },
        {
          label: "收费托管",
          value: "2"
        }
      ],
      translation: true,
      tagColors: {1:'blue',2:'red'}
    }
  },
  {
    title: "出库状态",
    dataIndex: "chuku_status",
    align:'center',
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "待出库",
          value: "1"
        },
        {
          label: "部分出库",
          value: "2"
        },
        {
          label: "已完成",
          value: "3"
        }
      ],
      translation: true,
      tagColors: {1:'grey',2:'red',3:'green'}
    }
  },
  
  {
    title: "仓储数量(件)",
    dataIndex: "pick_number",
    align:'center',
    formType: "input"
  },
  {
    title: "仓储重量(吨)",
    dataIndex: "pick_weight",
    align:'center',
    formType: "input"
  },
  // {
  //   title: "收货人",
  //   dataIndex: "receiver",
  //   formType: "input"
  // },
  // {
  //   title: "收货手机",
  //   dataIndex: "receiver_mobile",
  //   formType: "input"
  // },
  // {
  //   title: "收货电话",
  //   dataIndex: "receiver_tel",
  //   formType: "input"
  // },
  // {
  //   title: "区域",
  //   dataIndex: "area",
  //   formType: "input"
  // },
  // {
  //   title: "创建时间",
  //   dataIndex: "created_at",
  //   align:'center',
  //   formType: "range",
  //   search: true,
  //   addDisplay: false,
  //   editDisplay: false,
  //   showTime: true
  // },
  {
    title: "修改时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
defineExpose({ open })
</script>
<script> export default { name: 'warehouse:orderRecord' } </script>